package com.dycx.api.controller;

import com.dycx.common.RestResponse;
import com.dycx.common.vendor.oss.AliyunOss;
import com.dycx.system.service.OssFileService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "/file")
public class FileController {
    @Resource
    private OssFileService ossFileService;

    @PostMapping("/upload")
    public RestResponse<String> upload(@RequestParam("file") MultipartFile multipartFile) {
        String newUrl = AliyunOss.uploadStream(multipartFile);
        ossFileService.add(newUrl);
        return RestResponse.success(AliyunOss.addDomain(newUrl));
    }

    @GetMapping("/uploadNetworkFile")
    public RestResponse<String> uploadNetworkFile(String path) {
        String newUrl = AliyunOss.uploadNetworkFile(path, "http://www.tangexinxi.com/" + path);
        ossFileService.add(newUrl);
        return RestResponse.success(AliyunOss.addDomain(newUrl));
    }

}
